<%@ page import="hotsaucerecipes.Recipe" %>
<!doctype html>
<html>
<head>
    <g:javascript library="jquery" plugin="jquery"/>
    <meta name="layout" content="main">
    <g:set var="entityName" value="${message(code: 'recipe.label', default: 'Recipe')}"/>
    <title><g:message code="default.list.label" args="[entityName]"/></title>
</head>

<body>
<a href="#list-recipe" class="skip" tabindex="-1"><g:message code="default.link.skip.label"
                                                             default="Skip to content&hellip;"/></a>
<g:if test="${session?.user?.admin}">
    <div class="nav" role="navigation">
        <ul>
            <li><g:link class="create" action="create"><g:message code="default.new.label"
                                                                  args="[entityName]"/></g:link></li>
        </ul>
    </div>

</g:if>
<div id="list-recipe" class="content scaffold-list" role="main">
    <h1><g:message code="default.list.label" args="[entityName]"/></h1>
    <g:if test="${flash.message}">
        <div class="message" role="status">${flash.message}</div>
    </g:if>
    <table>
        <thead>
        <tr>

            <g:sortableColumn property="title" title="${message(code: 'recipe.title.label', default: 'Title')}"/>

            <g:sortableColumn property="ingredients"
                              title="${message(code: 'recipe.ingredients.label', default: 'Ingredients')}"/>

            <g:sortableColumn property="instructions"
                              title="${message(code: 'recipe.instructions.label', default: 'Instructions')}"/>
            <g:if test="${session?.user?.admin}"><th>Tweet</th></g:if>
        </tr>
        </thead>
        <tbody>
        <g:each in="${recipeInstanceList}" status="i" var="recipeInstance">
            <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
            <td><g:link action="show"
                        id="${recipeInstance.id}">${fieldValue(bean: recipeInstance, field: "title")}</g:link></td>

            <td>${fieldValue(bean: recipeInstance, field: "ingredients")}</td>

            <td>${fieldValue(bean: recipeInstance, field: "instructions")}</td>
            <g:if test="${session?.user?.admin}">
                <td id="tweet${recipeInstance.id}">
                    <button onClick="${remoteFunction(
                            controller: 'recipe',
                            action: 'tweet',
                            update: 'tweet' + "${recipeInstance.id}",
                            params: '\'id=' + "${recipeInstance.id}" + '\'')}">
                        Tweet
                    </button>
                </td>

                </tr></g:if>
        </g:each>
        </tbody>
    </table>

    <div class="pagination">
        <g:paginate total="${recipeInstanceTotal}"/>
    </div>
</div>
</body>
</html>
